
#ifndef __COLOR_H__
#define __COLOR_H__

#include "FileStream.h"

const float ucharToFloat = 1.0f / 255.0f;

class Color
{
public:

	// Constructor
	Color() { c.alpha = 255; }
	Color(ulong _color)
	{
		color = _color;
	}
	Color(uchar _red, uchar _green, uchar _blue, uchar _alpha = 255)
	{
		c.red = _red;
		c.green = _green;
		c.blue = _blue;
		c.alpha = _alpha;
	}
	Color(float _red, float _green, float _blue, float _alpha = 1.0f)
	{
		c.red   = (uchar)(_red   * 255.0f);
		c.green = (uchar)(_green * 255.0f);
		c.blue  = (uchar)(_blue  * 255.0f);
		c.alpha = (uchar)(_alpha * 255.0f);
	}

	void operator = (ulong _color)
	{
		color = _color;
	}

	uchar Red()   const { return c.red;   }
	uchar Green() const { return c.green; }
	uchar Blue()  const { return c.blue;  }
	uchar Alpha() const { return c.alpha; }

	float RedF()   const { return c.red   * ucharToFloat; }
	float GreenF() const { return c.green * ucharToFloat; }
	float BlueF()  const { return c.blue  * ucharToFloat; }
	float AlphaF() const { return c.alpha * ucharToFloat; }

	// Data
	union
	{
		ulong color;
		struct
		{
			uchar alpha;
			uchar red;
			uchar green;
			uchar blue;
		} c;
	};

	// Write
	void Write(FileStream &file)
	{
		if(file.IsBinary()) file.Write(((char*)&color), sizeof(ulong));
		else file.oFile << "(" << (int)c.red << ", " << (int)c.green << ", " << (int)c.blue << ", " << (int)c.alpha << ")\n";
	}

	// Read
	void Read(FileStream &file)
	{
		if(file.IsBinary()) file.Read(((char*)&color), sizeof(ulong));
		//else file << "(" << (int)c.red << ", " << (int)c.green << ", " << (int)c.blue << ", " << (int)c.alpha << ")\n";
	}
};

#define __white     0xFFFFFFFF
#define __lightgray 0xFFAFAFAF
#define __black     0xFF000000
#define __red       0xFFFF0000
#define __green     0xFF00FF00
#define __blue      0xFF0000FF
#define __yellow		0xFFFFFF00

#endif // __COLOR_H__